#import  <stdio.h>
#import  <libc.h>
#import  <objc/objc.h>
#import  <objc/NXBundle.h>	/* LocalizedString */
#import  <appkit/Panel.h>	/* NXRunAlertPanel() */
#import  "common.h"

static const char *err_message(int err)
{
	switch (err) {
	case Err_OPEN:
		return NXLocalizedString("Can't open file",
			NULL, Err_OPEN);
	case Err_FORMAT:
		return NXLocalizedString("Illegal image format",
			NULL, Err_FORMAT);
	case Err_MEMORY:
		return NXLocalizedString("Can't get working memory",
			NULL, Err_MEMORY);
	case Err_SHORT:
		return NXLocalizedString("Encountered unexpected EOF",
			NULL, Err_SHORT);
	case Err_ILLG:
		return NXLocalizedString("Illegal information included",
			NULL, Err_ILLG);
	case Err_IMPLEMENT:
		return NXLocalizedString("Unsupported image format",
			NULL, Err_IMPLEMENT);
	case Err_SAVE:
		return NXLocalizedString("Can't write into file",
			NULL, Err_SAVE);
	case Err_SAV_IMPL:
		return NXLocalizedString("Can't save this format",
			NULL, Err_SAV_IMPL);
	case Err_EPS_IMPL:
		return NXLocalizedString("Can't apply to EPS",
			NULL, Err_EPS_IMPL);
	case Err_NOFILE:
		return NXLocalizedString("There is no file",
			NULL, Err_NOFILE);
	default:
		break;
	}
	return NULL;
}

void errAlert(const char *file, int err)
{
	const char *msg = err_message(err);
	const char *title = NXLocalizedString("ERROR", NULL, ERROR);

	if (msg)
		NXRunAlertPanel(title, "%s :\n%s",
			NULL, NULL, NULL, file, msg);
}
